package com.shangxia.basic.common.mybatis.dynamicsource;

import com.github.pagehelper.PageInterceptor;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


/**
 * @ProjectName: MyDemo_zy
 * @ClassName: ResourceTypeEnum
 * @Time: 2020-04-01 20:13
 * @Author: zhou24
 * @Description:
 * @Experience:
 */
public class ResourceTypeEnum {
    public static final String BASE = "BASE";
    public static final String ORANGE = "ORANGE";
//    public static final String SYS = "SYS";

    public static final Map<String, ResourceType> dataSourceMap = new ConcurrentHashMap<>();

    static {
        register(BASE);
        register(ORANGE);
//        register(SYS);
    }

    public static void register(String key) {
        key = key.toUpperCase();
        if (!dataSourceMap.containsKey(key)) {
            dataSourceMap.put(key, new ResourceType(key));
        }
    }

    public static ResourceType getResourceType(String key) {
        register(key);
        return dataSourceMap.get(key.toUpperCase());
    }

    public static PageInterceptor getPageHelper(String key) {
        return dataSourceMap.get(key.toUpperCase()).getPageHelper();
    }
}
